package com.visionblue.business.ship.page.orders

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.visionblue.business.ship.R
import com.visionblue.business.ship.base.BaseActivity
import com.visionblue.business.ship.base.BaseVMActivity
import com.visionblue.business.ship.base.DefaultObserver
import com.visionblue.business.ship.ext.toast
import com.visionblue.business.ship.page.collection.CollectionViewModel
import kotlinx.android.synthetic.main.activity_apply_order_details.*
import org.koin.androidx.viewmodel.ext.android.getViewModel
import java.lang.StringBuilder
import java.math.BigDecimal
import java.math.RoundingMode

/**
 * des:
 * author: tekabo
 * date: 2021/3/31
 */
class OrderApplyDetailActivity : BaseVMActivity<OrderViewModel>(){
    private var orderId :String?=null

    override fun initVM(): OrderViewModel =getViewModel()
    override val layoutId: Int
        get() = R.layout.activity_apply_order_details

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        fl_detail_back.setOnClickListener{
            finish()
        }

        orderId = intent.getStringExtra("ApplyOrderId")

        if(orderId!=null){
            mViewModel.getOrderApplyDetails(orderId.toString())
        }else{
            toast { "orderId取值为null" }
        }

        data()
    }

    private fun data() {
        mViewModel.orderApplyDetailResult.observe(this,DefaultObserver(action = {
            if (it.data!=null){
                var content = it.data
                tv_order_no.text = content?.declareId


                var applyStr:String? = ""
                //申报污染物
                for (wasteInfo in content?.wasteInfoList) {
                    applyStr+=(wasteInfo.wasteName+",")
                }
                tv_apply_waste.text = applyStr?.substring(0,applyStr?.length-1)

                tv_apply_ship.text = content?.shipName
                tv_loc_point.text = content?.fishportName+"   "+content?.receiveLongitude+" , "+content?.receiveLatitude
               // tv_loc_point.text = content?.fishportName+"   "+BigDecimal(content?.receiveLongitude).setScale(2,RoundingMode.HALF_UP)+" , "+BigDecimal(content?.receiveLatitude).setScale(2,RoundingMode.HALF_UP)
                tv_receive_ship.text = content?.receiveShipName
                tv_receive_time.text = content?.receiveBeginTime+"-"+content?.receiveEndTime
                tv_create_tim.text = content?.createTime

                tv_apply_order_tim.text = content?.receiveTaskTime
                tv_task_area.text = content?.acturalWorkArea
                tv_work_time.text =content?.workBeginTime+"-"+content?.workEndTime
                //接收污染物
                var receiveStr:String? = ""
                for (receiveWasteInfo in content?.receiveWasteInfoList) {
                    receiveStr+=(receiveWasteInfo.wasteName+"  "+ BigDecimal(receiveWasteInfo.actualWeight).setScale(1,RoundingMode.HALF_UP))+"吨   "
                }
                tv_receive_waste.text = receiveStr
            }
        }))
    }

    companion object {
        fun start(context: Context, applyOrderId: String) {
            Intent(context, OrderApplyDetailActivity::class.java)
                    .putExtra("ApplyOrderId", applyOrderId)
                    .run {
                        context.startActivity(this)
                    }
        }
    }


}